<template>
  <div>
    <van-nav-bar
      title="联系人"
    />
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="getUserList"
    >
      <van-cell v-for="(item, i) in userList" :key="i" :title="item.username" @click="goChat(item)"/>
    </van-list>
  </div>
</template>
<script>
import {reqUserList} from '@/api/index'
import {getCookie} from '@/utils/index'
export default {
  data () {
    return {
      userList:[],
      list: [],
      loading: false,
      finished: false,
    }
  },
  mounted(){
    this.getUserList()
  },
  methods:{
    async getUserList () {
      const type = getCookie('type')
      const res = await reqUserList({type})
      if(res.status ===200){
        this.userList = res.data
                // 加载状态结束
        this.loading = false;
        // 数据全部加载完成
        if (res.data.length >= 1) {
          this.finished = true;
        }
      }
    },
    goChat(item){
      const uid = item._id
      const username = item.username
      this.$router.push(`/chatpanel/${uid}/${username}`)
    }
  }
}
</script>
<style lang='less' scoped>
/deep/ .van-cell{
  border-bottom: 1px solid #c6c6c6;
}
</style>